package cn.tedu.charging.cost.pojo.po;

import lombok.AccessLevel;
import lombok.Data;
import lombok.experimental.FieldDefaults;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;

import java.math.BigDecimal;

@Data
@FieldDefaults(level = AccessLevel.PRIVATE)
@Document(indexName = "charging_data_2407")
public class ChargingDataPO {
    @Id
    String id;

    Integer userId;
    /**
     * 同步次数
     */
    Integer count;
    /**
     * 订单号
     */
    String orderNo;
    /**
     * 总费用
     */
    BigDecimal total;
    /**
     * 充电量
     */
    Float chargingCapacity;
    Integer gunId;
    Long startTime;
    Long totalTime;

    public Boolean isFirst(){
        return count == 1;
    }
    public void setTotal(BigDecimal cost){
        if (isFirst()){
            this.total = cost;
        }else {
            this.total = this.total.add(cost);
        }
    }
    public Float getChargingCapacity(Float chargingCapacity){
        if (isFirst()){
            return this.chargingCapacity;
        }else {
            return chargingCapacity - this.chargingCapacity;
        }
    }
}
